import { apiUrl } from '@/api/url'
import $http from './http'

export const quickPayAPI = {
    // 快捷买币基本信息
    payInfo: ({ side }) => {
        return $http.get(`${apiUrl.wapi}api/pay/union/info`, { side })
    },
    // 快捷买币额度限制
    amountLimit: ({ symbol, fiatCode, side, amount = 1000 }) => {
        return $http.post(`${apiUrl.wapi}api/pay/union/amount-limit`, { symbol, fiatCode, side, amount })
    },
    // 快捷买币支付列表
    payMethods: ({ symbol, fiatCode, side, symbolAmount = 0, fiatCodeAmount = 0, amountType }) => {
        return $http.post(`${apiUrl.wapi}api/pay/union/list`, {
            symbol,
            fiatCode,
            side,
            symbolAmount,
            fiatCodeAmount,
            amountType,
        })
    },
}

export const thirdPayAPI = {
    //【第三方支付】第三方价格列表
    prices: ({ symbol = 'USDT', fiat_code = 'USD' }) => {
        return $http.post(`${apiUrl.wapi}api/otc/third/prices`, {
            symbol,
            fiat_code,
        })
    },
    // 【第三方支付】第三方可支付列表
    payments: ({ symbol, amount, fiat_code, fiat_amount }) => {
        return $http.post(`${apiUrl.wapi}api/otc/third/payments`, { symbol, amount, fiat_code, fiat_amount })
    },
    // 价格，交易对相关配置信息
    info: ({ fiat_code, symbol, channel }) => {
        return $http.get(`${apiUrl.wapi}api/otc/third/info2`, {
            fiat_code,
            symbol,
            channel,
        })
    },
    //【第三方支付】第三方基础信息接口
    paymentInfo: ({ symbol, fiat_code }) => {
        return $http.post(`${apiUrl.wapi}api/otc/third/info`, { symbol, fiat_code })
    },

    //【第三方支付】第三方支付下单接口
    generateOrder: ({ channel_name, symbol, amount, fiat_code, fiat_amount, quote_id }) => {
        const params = quote_id
            ? {
                  channel_name,
                  symbol,
                  amount,
                  fiat_code,
                  fiat_amount,
                  quote_id,
              }
            : {
                  channel_name,
                  symbol,
                  amount,
                  fiat_code,
                  fiat_amount,
              }
        return $http.post(`${apiUrl.wapi}api/otc/third/add-order`, params)
    },
    //【第三方支付】第三方支付订单列表接口
    orders: ({ channel_name, symbol, fiat_code, page, size }) => {
        return $http.post(`${apiUrl.wapi}api/otc/third/order-list`, {
            // channel_name,
            // symbol,
            // fiat_code,
            page,
            size,
        })
    },
    //【第三方支付】第三方支付订单详情接口
    orderDetail: ({ channel_name, id }) => {
        return $http.post(`${apiUrl.wapi}api/otc/third/order-detail`, { id })
    },
}

export const otcTrade = {
    // 商家信息
    merchantInfo: ({ merchant_uid }) => {
        return $http.get(`${apiUrl.wapi}v1/otc/merchant-info`, { merchant_uid })
    },
    // 买币详情
    rechargeDetail: ({ id }) => {
        return $http.get(`${apiUrl.wapi}v1/otc/recharge-detail`, { id })
    },
    // 卖币详情
    withdrawDetail: ({ id }) => {
        return $http.get(`${apiUrl.wapi}v1/otc/withdraw-detail`, { id })
    },
    // 买币
    recharge: ({ fiat_code, amount, symbol, pay_type }) => {
        return $http.post(`${apiUrl.wapi}v1/otc/recharge`, { fiat_code, amount, symbol, pay_type })
    },
    // 买币-确认
    confirmRecharge: ({ id }) => {
        return $http.post(`${apiUrl.wapi}v1/otc/recharge-confirm`, { id })
    },
    // 买币-取消
    cancelRecharge: ({ id }) => {
        return $http.post(`${apiUrl.wapi}v1/otc/recharge-cancel`, { id })
    },
    // 买币-申诉
    complaintRecharge: ({ id }) => {
        return $http.post(`${apiUrl.wapi}v1/otc/recharge-appeal`, { id })
    },
    // 买币-列表
    recharges: ({ order_state, page, size }) => {
        return $http.get(`${apiUrl.wapi}v1/otc/recharge-list`, { order_state, page, size })
    },
    // 卖币-创建订单
    sell: ({ symbol, amount, card_id, fiat_code, pay_type, ...params }) => {
        return $http.post(`${apiUrl.wapi}v1/otc/withdraw`, {
            symbol,
            amount,
            card_id,
            fiat_code,
            pay_type,
            ...params,
        })
    },
    // 卖币-订单列表
    withdraws: ({ order_state, page, size }) => {
        // 1.全部 2.已完成 3.未完成 4.已取消
        return $http.get(`${apiUrl.wapi}v1/otc/withdraw-list`, { order_state, page, size })
    },
    // 卖币-确认
    confirmWithdraw: ({ id }) => {
        return $http.post(`${apiUrl.wapi}v1/otc/withdraw-confirm`, { id })
    },
    // 卖币-取消
    cancelWithdraw: ({ id }) => {
        return $http.post(`${apiUrl.wapi}v1/otc/withdraw-cancel`, { id })
    },
    // 卖币-申诉
    complaintWithdraw: ({ id }) => {
        return $http.post(`${apiUrl.wapi}v1/otc/withdraw-appeal`, { id })
    },
    // 卖币-卖家确认
    confirmReceiveWithdraw: ({ id }) => {
        return $http.post(`${apiUrl.wapi}v1/otc/withdraw-fin-confirm`, { id })
    },
}

export const payMethodsAPI = {
    //发送邮箱验证码
    sendVerifyCode: ({ email }) => {
        return $http.post(`${apiUrl.wapi}sendVerifyCode`, {
            email,
        })
    },
    // 收款方式配置列表
    list: () => {
        return $http.get(`${apiUrl.wapi}api/otc/paymethod/list`)
    },
    // 收款方式字段
    fields: ({ pay_type, fiat_code }) => {
        return $http.get(`${apiUrl.wapi}api/otc/paymethod/field`, {
            pay_type,
            fiat_code,
        })
    },
    paycards: ({ pay_type }) => {
        return $http.get(`${apiUrl.wapi}api/otc/paycard/list`, {
            pay_type,
        })
    },
    add: (params) => {
        //fiat_code	text	是	IDR	法币
        // recipient_name	text	是	小王ba	姓名
        // routing_number	text	是	123456	银行号
        // account_number	text	是	789	银行账号
        // pay_type	text	是	1	支付类型 1银行卡
        // recipient_bank_name	text	是	天地银行	银行名称
        // phone_code	text	是	1314	验证码
        // state	text	是	1	1.上架 0下架
        return $http.post(`${apiUrl.wapi}api/otc/paycard/add`, params)
    },
    update: (params) => {
        return $http.post(`${apiUrl.wapi}api/otc/paycard/update`, params)
    },
    delete: (params) => {
        return $http.post(`${apiUrl.wapi}api/otc/paycard/delete`, params)
    },
    switch: ({ id, state }) => {
        return $http.post(`${apiUrl.wapi}api/otc/paycard/switch`, { id, state })
    },
}
